{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第二次练习\n",
    "\n",
    "+ 请**务必**交到**exer2**文件夹下，谢绝交到master下\n",
    "+ 请**不要改动**任何文件，拜托\n",
    "+ 请在10月16日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 食物和热量\n",
    "\n",
    "已知，以下食物每100g的千卡路里如下：\n",
    "\n",
    "小米粥 45  \n",
    "粗粮馒头 223  \n",
    "全麦面包 235  \n",
    "瘦猪肉 143  \n",
    "鸡翅 194  \n",
    "培根 181  \n",
    "火腿肠 212 \n",
    "\n",
    "建立一个空的字典，把上述键值对依此添加进去。 \n",
    "通过循环形式，显示，如“我吃了二两”+“小米粥”，“增加了”+“45”千卡路里。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "我吃了二两小米粥增加了45的热量\n",
      "我吃了二两粗粮馒头增加了223的热量\n",
      "我吃了二两全麦面包增加了235的热量\n",
      "我吃了二两瘦猪肉增加了143的热量\n",
      "我吃了二两鸡翅增加了194的热量\n",
      "我吃了二两培根增加了181的热量\n",
      "我吃了二两火腿肠增加了212的热量\n"
     ]
    }
   ],
   "source": [
    "food={}\n",
    "food['小米粥']='45'\n",
    "food['粗粮馒头']='223'\n",
    "food['全麦面包']='235'\n",
    "food['瘦猪肉']='143'\n",
    "food['鸡翅']='194'\n",
    "food['培根']='181'\n",
    "food['火腿肠']='212'\n",
    "for name,calorie in food.items():\n",
    "    print(\"我吃了二两\"+name+\"增加了\"+calorie+\"的热量\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 运动和消耗\n",
    "常见三种运动的消耗热量表：  \n",
    "慢走 (一小时4公里) 255 卡  \n",
    "慢跑 (一小时9公里) 655 卡  \n",
    "羽毛球（一小时） 440 卡  \n",
    "\n",
    "模仿课件3-dict_set中的cell[9]做个刷题，直到答对而且答完为止。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "慢走 (一小时4公里)\n",
      "\n",
      "这个运动耗多少卡？\n",
      "255卡  655卡  440卡  \n",
      "- 255卡\n",
      "你真NiuPi！\n",
      "\n",
      "慢跑 (一小时9公里)\n",
      "\n",
      "这个运动耗多少卡？\n",
      "255卡  655卡  440卡  \n",
      "- 655卡\n",
      "你真NiuPi！\n",
      "\n",
      "羽毛球（一小时）\n",
      "\n",
      "这个运动耗多少卡？\n",
      "255卡  655卡  440卡  \n",
      "- 440卡\n",
      "你真NiuPi！\n"
     ]
    }
   ],
   "source": [
    "fat = { '255卡': '慢走 (一小时4公里)',\n",
    "        '655卡': '慢跑 (一小时9公里)',\n",
    "        '440卡': '羽毛球（一小时）',\n",
    "       }\n",
    "def show(fat):\n",
    "    display = \"\"\n",
    "    for word in fat.keys():\n",
    "        display += word + '  '\n",
    "    print(display)\n",
    "    \n",
    "for sport in fat.values():\n",
    "    \n",
    "    print(\"\\n%s\" % sport)\n",
    "    correct = False\n",
    "    while not correct:\n",
    "        print(\"\\n这个运动耗多少卡？\")\n",
    "        show(fat)\n",
    "        cal = input(\"- \")\n",
    "        \n",
    "        if cal in fat:\n",
    "            if fat[cal] == sport:\n",
    "                print(\"你真NiuPi！\")\n",
    "                correct = True\n",
    "        else:\n",
    "            print(\"真不是你傻，是问题太变态！\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 江西最高山\n",
    "\n",
    "[江西最高的十座山]{http://jx.ifeng.com/a/20160628/4693979_0.shtml}\n",
    "\n",
    "请模仿上例，创建包含山名和海拔的dict，并按如下形式循环输出：  \n",
    "“黄岗山海拔2157.8米”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "九岭头海拔1794米\n",
      "五虎岗海拔1891米\n",
      "军峰山海拔1761米\n",
      "南风面海拔2120米\n",
      "独竖尖海拔2129米\n",
      "玉京峰海拔1817米\n",
      "过风坳海拔1887米\n",
      "金顶海拔1918.3米\n",
      "黄岗山海拔2158米\n",
      "齐云山海拔2069米\n"
     ]
    }
   ],
   "source": [
    "python_words = {'黄岗山': '2158',\n",
    "                    '独竖尖': '2129',\n",
    "                    '南风面': '2120',\n",
    "                    '齐云山': '2069',\n",
    "                    '金顶': '1918.3',\n",
    "                    '五虎岗': '1891',\n",
    "                    '过风坳': '1887',\n",
    "                    '玉京峰': '1817',\n",
    "                    '九岭头': '1794',\n",
    "                    '军峰山': '1761',\n",
    "                }\n",
    "for word in sorted(python_words.keys()):\n",
    "     print(\"%s海拔%s米\" % (word.title(), python_words[word]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 为室友打一波广告\n",
    "请参照课件3-dict_set中的cell[15]“卖室友”吧。  \n",
    "第一层dict的key可自选，如身高、爱好、技能等等。\n",
    "并以以下形式循环输出：  \n",
    "我知道的XXX，TA:  \n",
    "身高：160  \n",
    "爱好：吸猫  \n",
    "技能：python  \n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "价格：998元/位\n",
      "128聚仙阁室员陈冲:\n",
      "身高: 189\n",
      "爱好: 看体育类比赛\n",
      "喜欢的游戏: 王者荣耀\n",
      "一分钱一分货，大家走过路过不要错过\n",
      "128聚仙阁室员余平根:\n",
      "身高: 177\n",
      "爱好: 和朋友出去浪\n",
      "喜欢的游戏: 王者荣耀\n",
      "一分钱一分货，大家走过路过不要错过\n",
      "128聚仙阁室员薛国富:\n",
      "身高: 178\n",
      "爱好: 打篮球\n",
      "喜欢的游戏: 王者荣耀\n",
      "一分钱一分货，大家走过路过不要错过\n"
     ]
    }
   ],
   "source": [
    "roommates= {'陈冲': {'身高': '189', '爱好': '看体育类比赛', '喜欢的游戏':'王者荣耀'},\n",
    "        '余平根': {'身高': '177', '爱好': '和朋友出去浪', '喜欢的游戏':'王者荣耀'},\n",
    "        '薛国富': {'身高': '178', '爱好': '打篮球', '喜欢的游戏':'王者荣耀'},\n",
    "        }\n",
    "\n",
    "print(\"价格：998元/位\")\n",
    "for roommates_name, roommates_information in roommates.items():\n",
    "    print(\"128聚仙阁室员%s:\" % roommates_name.title())\n",
    "    print(\"身高: \" + roommates_information['身高'])\n",
    "    print(\"爱好: \" + roommates_information['爱好'])\n",
    "    print(\"喜欢的游戏: \" + roommates_information['喜欢的游戏'])\n",
    "    print(\"一分钱一分货，大家走过路过不要错过\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
